package zsh.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import zsh.domain.User;

import java.util.Arrays;
import java.util.List;

@Controller
@RequestMapping("/User")
public class UserController {
    @RequestMapping("/printUser")
    @ResponseBody
    public String printUser(String name, int age){
        System.out.println("姓名:"+name+",年龄:"+age);
        return "success";
    }

    @RequestMapping("/printObject")
    @ResponseBody
    public String printObject(User user){
        System.out.println("姓名:"+user.getName()+",年龄:"+user.getAge());
        return "success";
    }

    @RequestMapping("/printArr")
    @ResponseBody
    public String printArr(String[] arr){
        System.out.println("名单:"+Arrays.toString(arr));
        return "success";
    }

    @RequestMapping("/printList")
    @ResponseBody
    public String printList(@RequestParam List<String> name){
        System.out.println("人员:"+name);
        return "success";
    }

    @RequestMapping("/printJson")
    @ResponseBody
    public String printJson(@RequestBody User user ){
//        System.out.println("信息:"+user);
        System.out.println("姓名:"+user.getName());
        System.out.println("年龄:"+user.getAge());
        return "success";
    }

    @RequestMapping("/printJsonList")
    @ResponseBody
    public String printJsonList(@RequestBody List<User> users ){
        users.forEach(System.out::println);
        return "success";
    }

    @RequestMapping("/printPath/{name}")
    @ResponseBody
    public String printPath(@PathVariable String name ){
        System.out.println("名字是:"+name);
        return "success";
    }

    //响应页面
    @RequestMapping("/front")
    public String gotoPage(){
        System.out.println("跳转");
        return "FrontPage";
    }
}
